package com.richpencil.modules.repository;

import com.richpencil.modules.ki.domain.Log;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 *
 * @date 2018-11-24
 */
@Repository
public interface LogRepository extends JpaRepository<Log,String>, JpaSpecificationExecutor {

    /**
     * 获取一个时间段的IP记录
     * @param date1
     * @param date2
     * @return
     */
    @Query(value = "select count(*) FROM (select request_ip FROM sas_log where create_time>=CONCAT(:start,' 00:00:00') and create_time<=CONCAT(:end,' 23:59:59z') GROUP BY request_ip) query ",nativeQuery = true)
    Long findIp(@Param("start") String start,@Param("end") String end);

    /**
     * findExceptionById
     * @param id
     * @return
     */
    @Query(value = "select exception_detail FROM sas_log where id = ?1",nativeQuery = true)
    String findExceptionById(String id);
}
